//
//  HBHCommentViewController.m
//  HubeiHotel
//
//  Created by 张露杰 on 18/4/2.
//  Copyright © 2018年 张露杰. All rights reserved.
//

#import "HBHCommentViewController.h"
#import "TZImagePickerController.h"
#import "ImageVCell.h"
#import "SelfTextView.h"

@interface HBHCommentViewController ()
@property (nonatomic,strong)UICollectionView *collectionView;
@property (nonatomic,strong)SelfTextView *textInputV;
@property (nonatomic, copy) NSString *content;
@end

@implementation HBHCommentViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self creatView];
}

-(void)creatView
{
    [self initTitleWithTitle:@"评论"];
    [self initLeftBarButtonWithImage:@"back"];
    [self initRightBarButtonWithTitle:@"发送" andTitleColor:[UIColor whiteColor] andFont:16*screenW_6];
    self.view.backgroundColor = [UIColor whiteColor];
    SelfTextView *textInputV =[[SelfTextView alloc]initWithFrame:CGRectMake(15*screenW_6,15*screenW_6,SCREENW-30*screenW_6,150*screenW_6) text:@"" PlaceHodel:@"请输入详细的文字内容～"];
    textInputV.backgroundColor = backColor;
    [self.view addSubview:textInputV];
    __weak typeof(self) weakSelf = self;
    textInputV.blcok =  ^(NSString *text){
        weakSelf.content = text;
    };
}

-(void)onTapRightBarButton
{
    if (_content.length == 0) {
        [TomamaUI creatAlertWithTarget:self message:@"请输入您的评论" timeInterval:2];
        return;
    }
    
    [HudHelper showProgressHudWithMessage:@"" toView:self.view];
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        [HttpRequest PostrequestUrl:@"/post/addPostComment" Dic:@{@"post.id":_postId,@"user.id":[Storage getToken],@"content":_content} completion:^(NSDictionary *responseDic) {
            dispatch_async(dispatch_get_main_queue(), ^{
                [HudHelper hideHudToView:self.view];
                if ([responseDic[@"success"] boolValue]) {
                    [TomamaUI creatAlertWithTarget:self message:@"评论成功" timeInterval:2 block:^{
                        [self.navigationController popViewControllerAnimated:YES];
                    }];
                }else{
                    [TomamaUI creatAlertWithTarget:self message:responseDic[@"msg"] timeInterval:2];
                }
            });
        }];
    });
}



@end
